define(['jquery', 'bootstrap', 'frontend', 'form', 'template', 'layui', 'echarts', 'echarts-theme'], function ($, undefined, Frontend, Form, Template, Layui, Echarts, undefined) {
    var validatoroptions = {
        ignore: ':hidden',
        invalid: function (form, errors) {
            $.each(errors, function (i, j) {
                Layer.msg(j);
            });
        }
    };
    var form = layui.form, dropdown = layui.dropdown, layer = layui.layer, laypage = layui.laypage, upload = layui.upload, laydate = layui.laydate;
    var Controller = {

        index: function () {
            form.on('select(year)', function(data){
                $('.in_main2 .search_item .item.active').trigger('click');
            });

            $(document).on('click', '.in_main2 .search_item .item', function () {
                $(this).addClass('active').siblings('.item').removeClass('active');
                var that = $(this);
                let type = that.data('value');
                let year = $('select[name=year]').val();
                Fast.api.ajax({
                    url: 'manage/charts',
                    data: {year: year, type: type},
                }, function (data, ret) {
                    console.log(data)
                    Controller.api.charts(data.year, data.data);
                    return false;
                }, function (data, ret) {
                    Layer.msg(ret.msg);
                    return false;
                });
            });

            $('.in_main2 .search_item .item:first').trigger('click');
        },

        payslip_add: function () {

            var uploadInst = upload.render({
                elem: '#file',
                url: Config.upload.uploadurl,
                accept: 'file', // 只允许上传图片
                acceptMime: 'xlsx', // 打开文件选择器时只显示图片
                done: function (res) {
                    if (res.code === 1) {
                        $('input[name="row[file]"]').val(res.data.url);
                        let url = res.data.url;
                        $('.upload_url').text(url.substring(url.lastIndexOf('/') + 1));
                        return Layer.msg('上传成功');
                    }
                    return Layer.msg('上传失败');
                }
            });

            var addname = $('#add_name');
            var postform = $('#post-form');
            var typeform = $('#type-form');
            var progress_id = null;

            postform.data("validator-options", validatoroptions);
            Form.api.bindevent(postform, function (data, ret) {

                clearInterval(progress_id);
                layui.element.progress('number', '100%');
                $('.progress_text').text($('.layui-progress-bar').attr('lay-percent'));

                $('.import_success').text(data.statistics.import_success);
                $('.import_error').text(data.statistics.import_error);
                $('.batch_success').text(data.statistics.batch_success);
                $('.batch_error').text(data.statistics.batch_error);
                $('.scgzb_pop .scgzb_item3, .scgzb_pop .pop_but').removeClass('hide');
                $('.scgzb_pop .pop_but a').attr('href', data.next_url);

                if (data.statistics.import_error > 0) {
                    $('.error_msg').on('click', function () {
                        var content = '<table class="layui-table">';
                        $.each(data.error_json, function (k, v) {
                            content += '<tr><td style="padding: 8px 20px;">' + v + '</td><td style="padding: 8px 20px;">重复导入</td></tr>';
                        });
                        content += '</table>';
                        Layer.open({
                            type: 1,
                            area: ["400px", "250px"],
                            content: content
                        });
                    }).removeClass('hide');
                }
                if (data.statistics.batch_error > 0) {
                    $('.batch_msg').attr('href', data.next_url).removeClass('hide');
                }

                return false;

            }, function (data, ret) {

                Layer.msg(ret.msg);
                return false;

            }, function () {

                $('.type_name').text($('select[name="row[payslip_type]"] option:selected').text());
                $('.month_name').text($('input[name="row[month]"]').val());
                $('.file_name').text($('.upload_url').text());

                $('.scgzb_pop').fadeIn();
                $('body').css('overflow','hidden');

                var progress_rate = 0;
                progress_id = setInterval(function () {
                    progress_rate += 1;
                    if (progress_rate <= 100) {
                        layui.element.progress('number', progress_rate + '%');
                        $('.progress_text').text($('.layui-progress-bar').attr('lay-percent'));
                    } else {
                        clearInterval(progress_id);
                    }
                }, 50);
            });

            typeform.data("validator-options", validatoroptions);
            Form.api.bindevent(typeform, function (data, ret) {
                Layer.confirm(ret.msg, {icon: 1, closeBtn: 0, btn: ['确定']}, function () {
                    window.location.reload();
                });
                return false;
            }, function (data, ret) {
                Layer.msg(ret.msg);
                return false;
            });

            $(document).on('click', '.upload_alert', function () {
                Layer.confirm('请先下载模板文件，将数据填充完整后，另存为标准的.xlsx文件，再上传至本系统。', {icon: 3, closeBtn: 0, btn: ['确定']}, function () {
                    Layer.closeAll();
                });
            });

            $(document).on('click', '.sz_but', function () {
                $('.fxlx_pop').fadeIn();
                $('body').css('overflow','hidden');
            });

            $(document).on('click', '.add_but', function () {
                if ($.trim(addname.val()) === '') {
                    Layer.msg('请输入类型名称');
                    return false;
                }
                $('.btn-append').trigger('click');
                $(document).find('.fieldlist input:first').change();
            });

            $(document).on('fa.event.appendfieldlist', '#type-form .btn-append', function (e, obj) {
                if ($.trim($(obj).find('input:first').val()) === '') {
                    var max = 1;
                    $('.type_list .type_id').each(function (k, v) {
                        let num = String(parseInt($(this).val())) === 'NaN' ? max : parseInt($(this).val()) + 1;
                        max = max >= num ? max : num;
                    });
                    $(obj).find('input:first').val(max);
                    $(obj).find('input:last').val(addname.val());
                    addname.val('');
                }
            });

            laydate.render({
                elem: '#render',
                type: 'month'
            });

            Controller.api.bindpop();
        },

        payslip_check: function () {

            $(document).on('click', 'thead .checkbox', function () {
                if ($(this).hasClass('active')) {
                    $(this).removeClass('active');
                    $(this).parents('thead').siblings('tbody').find('.checkbox').removeClass('active');
                } else {
                    $(this).addClass('active');
                    $(this).parents('thead').siblings('tbody').find('.checkbox').addClass('active');
                }
            });

            $(document).on('click', 'tbody .checkbox', function () {
                $(this).toggleClass('active');
                var act_num = $(this).parents('tbody').find('.checkbox.active').length, all_num = $(this).parents('tbody').find('.checkbox').length;
                if (act_num === all_num) {
                    $(this).parents('tbody').siblings('thead').find('.checkbox').addClass('active');
                } else {
                    $(this).parents('tbody').siblings('thead').find('.checkbox').removeClass('active');
                }
            });

            $(document).on('change', 'tbody .field', function () {
                var data = {id: $(this).data('id'), type: 'change'};
                $.each($(this).closest('tr').find('.field'), function () {
                    data[$(this).data('name')] = $(this).val();
                });
                Fast.api.ajax({
                    url: 'manage/payslip_check',
                    data: data
                }, function (data, ret) {
                    Layer.msg(ret.msg);
                    return false;
                }, function (data, ret) {
                    Layer.msg(ret.msg);
                    return false;
                });
            });

            $(document).on('click', 'tbody .cancel_but', function () {
                var data = {id: $(this).data('id'), type: 'cancel'};
                Layer.confirm('确定要取消匹配吗？', {icon: 3}, function () {
                    Fast.api.ajax({
                        url: 'manage/payslip_check',
                        data: data
                    }, function (data, ret) {
                        Layer.confirm(ret.msg, {icon: 1, closeBtn: 0, btn: ['确定']}, function () {
                            window.location.reload();
                        });
                        return false;
                    }, function (data, ret) {
                        Layer.msg(ret.msg);
                        return false;
                    });
                });
            });

            $(document).on('click', 'tbody .del_but', function () {
                var data = {id: $(this).data('id'), type: 'remove'};
                Layer.confirm('确定要删除当前记录吗？', {icon: 3}, function () {
                    Fast.api.ajax({
                        url: 'manage/payslip_check',
                        data: data
                    }, function (data, ret) {
                        Layer.confirm(ret.msg, {icon: 1, closeBtn: 0, btn: ['确定']}, function () {
                            window.location.reload();
                        });
                        return false;
                    }, function (data, ret) {
                        Layer.msg(ret.msg);
                        return false;
                    });
                });
            });

            $(document).on('click', '.del_all', function () {
                var ids = [];
                $('tbody .checkbox.active').each(function (k, v) {
                    ids.push($(this).data('id'));
                });
                if (!ids.length) {
                    Layer.msg('请至少选择一条记录');
                    return false;
                }
                var data = {ids: ids, type: 'batch_remove'};
                Layer.confirm('确定要删除所选记录吗？', {icon: 3}, function () {
                    Fast.api.ajax({
                        url: 'manage/payslip_check',
                        data: data
                    }, function (data, ret) {
                        Layer.confirm(ret.msg, {icon: 1, closeBtn: 0, btn: ['确定']}, function () {
                            window.location.reload();
                        });
                        return false;
                    }, function (data, ret) {
                        Layer.msg(ret.msg);
                        return false;
                    });
                });
            });

            $(document).on('click', 'tbody .pipei_but', function () {
                $('.pipei_pop input[name=id]').val($(this).data('id'));
                $('.pipei_pop').fadeIn().find('.amount').text($(this).data('amount'));
                $('body').css('overflow','hidden');
            });

            $(document).on('click', '.pipei_pop .search_but', function () {
                var nickname = $('.pipei_pop input[name=nickname]').val();
                if ($.trim(nickname) === '') {
                    Layer.msg('请输入员工姓名');
                    return false;
                }
                var data = {type: 'user_search', nickname: nickname};
                Fast.api.ajax({
                    url: 'manage/payslip_check',
                    data: data
                }, function (data, ret) {
                    $('.pipei_list').html(Template('user_tpl', data));
                    return false;
                }, function (data, ret) {
                    Layer.msg(ret.msg);
                    return false;
                });
            });

            $(document).on('click', '.pipei_pop .pipei_item2', function () {
                $('.pipei_pop input[name=user_id]').val($(this).data('id'));
                $(this).addClass('active').siblings('.pipei_item2').removeClass('active');
            });

            $(document).on('click', '.back_but', function () {
                var url = $(this).data('url');
                Layer.confirm('确定重新上传工资表吗？', {icon: 3}, function () {
                    window.location.href = url;
                });
            });

            var searchform = $('#search-form');
            form.on('select(department_id)', function(data){
                $('input[name=page]').val(1);
                searchform.submit();
            });

            var bindform = $('#bind-form');
            bindform.data("validator-options", validatoroptions);
            Form.api.bindevent(bindform, function (data, ret) {
                Layer.confirm(ret.msg, {icon: 1, closeBtn: 0, btn: ['确定']}, function () {
                    window.location.reload();
                });
                return false;
            }, function (data, ret) {
                Layer.msg(ret.msg);
                return false;
            });

            var page_el = $('#laypage');
            Controller.api.bindpages(searchform, page_el.data('total'), page_el.data('per_page'), page_el.data('current_page'));
            Controller.api.bindpop();
        },

        payslip_confirm: function () {

            $(document).on('click', '.liji_but, .dingshi_but', function () {
                $('.dingshi_pop').fadeIn();
                $('body').css('overflow','hidden');
                $('input[name=status]').val($(this).data('status'));
                $('.status_' + $(this).data('status')).removeClass('hide').siblings('.status').addClass('hide');
            });

            laydate.render({
                elem: '#render',
                type: 'datetime'
            });

            Controller.api.bindpop();
            Controller.api.bindevent();
        },

        payslip_settings: function () {

            $(document).on('click', '.checkbox', function () {
                if ($(this).hasClass('active')) {
                    $(this).removeClass('active');
                    $('input[name="row[title]"]').removeAttr('readonly').val('').focus();
                } else {
                    $(this).addClass('active');
                    $('input[name="row[title]"]').attr('readonly', 'readonly').val(Config.default_title);
                    $('.phone_content .text h3').text(Config.default_title);
                }
                $(this).find('input').val($(this).hasClass('active') ? 1 : 0);
                $('.text_title').trigger('change');
            });

            $(document).on('keyup', 'input[name="row[title]"]', function () {
                var text = $(this).val();
                $('.phone_content .text h3').text(text);
            });

            $(document).on('keyup', 'textarea[name="row[zhaiyao]"]', function () {
                var text = $(this).val();
                $('.phone_content .text p').text(text);
            });

            $(document).on('click', '.switch', function () {
                if ($(this).parents('.layui-form-item').hasClass('read')) {
                    if ($(this).hasClass('active')) {
                        $(this).removeClass('active');
                        $(this).parents('.layui-form-item').siblings('.read_item').slideUp();
                    } else {
                        $(this).addClass('active');
                        $(this).parents('.layui-form-item').siblings('.read_item').slideDown();
                    }
                } else {
                    $(this).toggleClass('active');
                }
                $(this).find('input').val($(this).hasClass('active') ? 1 : 0);
            });

            var uploadInst = upload.render({
                elem: '#file',
                url: Config.upload.uploadurl, //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
                accept: 'images', // 只允许上传图片
                acceptMime: 'image/*',  // 打开文件选择器时只显示图片
                before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('.phone_content img').attr('src', result); //图片链接（base64）
                    });
                },
                done: function (res) {
                    if (res.code === 1) {
                        $('input[name="row[image]"]').val(res.data.url);
                        return Layer.msg('上传成功');
                    }
                    return Layer.msg('上传失败');
                }
            });

            Controller.api.bindevent();
        },

        address_book: function () {

            var postform = $('#post-form');
            var resetform = $('#reset-form');

            require(['jstree'], function () {
                var channeltree = $('#channeltree');
                channeltree.jstree({
                    "themes": {
                        "stripes": true
                    },
                    "checkbox": {
                        "keep_selected_style": false,
                    },
                    "types": {
                        "group": {
                            "icon": '/assets/manage/images/icon_01.png',
                        },
                        "disabled": {
                            "check_node": false,
                            "uncheck_node": false
                        }
                    },
                    'plugins': ["types", "checkbox"],
                    "core": {
                        "multiple": false,
                        'check_callback': true,
                        "data": Config.groupList
                    }
                });
                channeltree.on("loaded.jstree", function (e, data) {
                    var level = 3;
                    var obj = data.instance._model.data;
                    var arr = Object.values(obj);//对象转化为数组
                    var arrLevel = []; //定义一个不大于n级节点的空数组
                    var levels = []; //定义一个等于n级节点的空数组
                    arr.map(function (item, index) {//遍历
                        if (item.parents.length <= level) { //如果节点<=4级（包含的父结点个数<=4）
                            arrLevel.push(item.id)//空数组赋值
                        }
                        if (item.parents.length === level) {//如果节点为4级（包含的父结点个数=4）
                            levels.push(item.id)
                        }
                    })
                    for (let i in arrLevel) {
                        $('#channeltree').jstree().open_node(arrLevel[i]);
                    }
                    for (let j in levels) {
                        $('#channeltree').jstree().close_all(levels[j]);
                    }
                });
                channeltree.on("changed.jstree", function (e, data) {
                    $('input[name=department_id]').val(data.selected.join(","));
                    $('input[name=page]').val(1);
                    postform.submit();
                    return false;
                });
            });

            Template.helper("Moment", Moment);

            Form.api.bindevent(postform, function (data, ret) {
                $('.lists').html(Template('list_tpl', data));
                Controller.api.bindpages(postform, data.total, data.per_page, data.current_page);
                return false;
            }, function (data, ret) {
                Layer.msg(ret.msg);
                return false;
            });

            form.on('select(status)', function(data){
                $('input[name=page]').val(1);
                postform.submit();
            });

            postform.submit();

            resetform.data("validator-options", validatoroptions);
            Form.api.bindevent(resetform, function (data, ret) {
                Layer.msg(ret.msg);
                $('.close').trigger('click');
                resetform[0].reset();
                return false;
            }, function (data, ret) {
                Layer.msg(ret.msg);
                return false;
            });

            // 点击同步
            $(document).on('click', '.btn-sync', function () {
                var that = $(this);
                Layer.confirm('手动同步将占用大量系统资源，确定立即同步吗？', {icon: 3}, function () {
                    that.html('<i class="fa fa-refresh fa-spin"></i> 正在同步');
                    Layer.closeAll();
                    Fast.api.ajax({
                        url: 'manage/address_sync',
                        data: {}
                    }, function (data, ret) {
                        that.html('<i class="fa fa-refresh"></i> 同步信息');
                        Layer.confirm('同步已完成', {icon: 1, closeBtn: 0, btn: ['确定']}, function () {
                            window.location.reload();
                        });
                        return false;
                    }, function (data, ret) {
                        that.html('<i class="fa fa-refresh"></i> 同步信息');
                        Layer.msg(ret.msg);
                        return false;
                    });
                });
            });

            $(document).on('click', '.switch_group', function () {
                var that = $(this);
                Layer.confirm('确定要操作吗？', {icon: 3}, function () {
                    Fast.api.ajax({
                        url: 'manage/switch_group',
                        data: {id: that.data('id'), value: that.data('value')}
                    }, function (data, ret) {
                        Layer.closeAll();
                        postform.submit();
                        return false;
                    }, function (data, ret) {
                        Layer.msg(ret.msg);
                        return false;
                    });
                });
            });

            $(document).on('click', '.cz_but', function () {
                var that = $(this);
                Layer.confirm('确定要清除手势密码吗？', {icon: 3}, function () {
                    Fast.api.ajax({
                        url: 'manage/clear_pwd',
                        data: {id: that.data('id')}
                    }, function (data, ret) {
                        Layer.closeAll();
                        Layer.msg(ret.msg);
                        return false;
                    }, function (data, ret) {
                        Layer.msg(ret.msg);
                        return false;
                    });
                });




                // $('input[name=uid]').val(that.data('id'));
                // $('.cz_pop').fadeIn();
                // $('body').css('overflow', 'hidden');
            });

            Controller.api.bindpop();
        },

        payslip_list: function () {

            var searchform = $('#search-form');
            form.on('select(type)', function(data){
                $('input[name=page]').val(1);
                searchform.submit();
            });

            laydate.render({
                elem: '#year',
                type: 'year',
                done: function (value, date) {
                    $('input[name=page]').val(1);
                    searchform.submit();
                }
            });

            var page_el = $('#laypage');
            Controller.api.bindpages(searchform, page_el.data('total'), page_el.data('per_page'), page_el.data('current_page'));
        },

        payslip_detail: function () {

            var searchform = $('#search-form');
            form.on('select(status)', function(data){
                $('input[name=page]').val(1);
                searchform.submit();
            });

            $(document).on('click', '.ck_but', function () {
                var that = $(this);
                Fast.api.ajax({
                    url: 'manage/payslip_detail',
                    data: {id: that.data('id'), logs_id: that.data('logs_id')}
                }, function (data, ret) {
                    $('.ck_pop .fsjl_content').html(Template('view_tpl', data));
                    $('.ck_pop').fadeIn();
                    $('body').css('overflow', 'hidden');
                    return false;
                }, function (data, ret) {
                    Layer.msg(ret.msg);
                    return false;
                });
            });

            $(document).on('click', '.edit_but', function () {
                var that = $(this);
                Fast.api.ajax({
                    url: 'manage/payslip_detail',
                    data: {id: that.data('id'), logs_id: that.data('logs_id')}
                }, function (data, ret) {
                    $('.edit_pop .fsjl_content').html(Template('edit_tpl', data));
                    $('.edit_pop').fadeIn();
                    $('body').css('overflow', 'hidden');
                    return false;
                }, function (data, ret) {
                    Layer.msg(ret.msg);
                    return false;
                });
            });

            $(document).on('click', '.send_but', function () {
                var that = $(this);
                Layer.confirm('确定要重发吗？', {icon: 3}, function () {
                    Fast.api.ajax({
                        url: 'manage/payslip_send',
                        data: {id: that.data('id'), logs_id: that.data('logs_id')}
                    }, function (data, ret) {
                        Layer.confirm(ret.msg, {icon: 1, closeBtn: 0, btn: ['确定']}, function () {
                            window.location.reload();
                        });
                        return false;
                    }, function (data, ret) {
                        Layer.msg(ret.msg);
                        return false;
                    });
                });
            });

            $(document).on('click', '.save_but', function () {
                var data = {id: $(this).data('id')};
                $.each($(this).closest('.fsjl_content').find('.field'), function () {
                    data[$(this).data('name')] = $(this).val();
                });
                Fast.api.ajax({
                    url: 'manage/payslip_save',
                    data: data
                }, function (data, ret) {
                    Layer.msg(ret.msg);
                    return false;
                }, function (data, ret) {
                    Layer.msg(ret.msg);
                    return false;
                });
            });

            $(document).on('click', '.export_but', function () {
                window.open(Fast.api.fixurl('manage/payslip_export?id=' + $(this).data('id')));
            });

            $(document).on('click', '.resend_but', function () {
                var data = {id: $(this).data('id')};
                Layer.confirm('确定要全部重发吗？确定后将会立即执行。', {icon: 3}, function () {
                    Fast.api.ajax({
                        url: 'manage/payslip_resend',
                        data: data
                    }, function (data, ret) {
                        Layer.confirm(ret.msg, {icon: 1, closeBtn: 0, btn: ['确定']}, function () {
                            window.location.reload();
                        });
                        return false;
                    }, function (data, ret) {
                        Layer.msg(ret.msg);
                        return false;
                    });
                });
            });

            $(document).on('click', '.f_item_title', function () {
                if ($(this).hasClass('active')) {
                    $(this).removeClass('active').siblings('.item_list').removeClass('show');
                } else {
                    $(this).addClass('active').siblings('.item_list').addClass('show');
                }
            });

            var page_el = $('#laypage');
            Controller.api.bindpages(searchform, page_el.data('total'), page_el.data('per_page'), page_el.data('current_page'));
            Controller.api.bindpop();
        },

        payslip_feedback: function () {

            $(document).on('click', '.cl_but', function () {
                var that = $(this);
                Fast.api.ajax({
                    url: 'manage/payslip_feedback_detail',
                    data: {id: that.data('id')}
                }, function (data, ret) {
                    $('.cl_pop #post-form').html(Template('pop_tpl', data));
                    $('.cl_pop').fadeIn();
                    $('body').css('overflow', 'hidden');
                    return false;
                }, function (data, ret) {
                    Layer.msg(ret.msg);
                    return false;
                });
            });

            $(document).on('click','.cl_item2 .icon-shanchu',function(){
                var that = $(this);
                Layer.confirm('确定要删除吗？', {icon: 3}, function () {
                    Fast.api.ajax({
                        url: 'manage/payslip_feedback_remove',
                        data: {id: that.data('id'), key: that.data('key')}
                    }, function (data, ret) {
                        Layer.closeAll();
                        $('.view_btn_' + that.data('id')).trigger('click');
                        return false;
                    }, function (data, ret) {
                        Layer.msg(ret.msg);
                        return false;
                    });
                });
            });

            var postform = $('#post-form');
            postform.data("validator-options", validatoroptions);
            Form.api.bindevent(postform, function (data, ret) {
                Layer.msg(ret.msg);
                window.location.reload();
                return false;
            }, function (data, ret) {
                Layer.msg(ret.msg);
                return false;
            });

            Controller.api.bindpop();
        },

        api: {
            bindpop: function () {
                $(document).on('click', '.layui-btn-primary, .close', function () {
                    $(this).parents('.pop').fadeOut();
                    $('body').removeAttr('style');
                });

                $(document).on('click', '.pop', function (e) {
                    var div_box = $('.pop_content');
                    if (!div_box.is(e.target) && div_box.has(e.target).length === 0) {
                        $(this).fadeOut();
                        $('body').removeAttr('style');
                    }
                });
            },
            bindpages: function (form, total, per_page, current_page) {
                laypage.render({
                    elem: 'laypage', // 存放分页控件的容器
                    curr: current_page,
                    count: total, //数据总数。一般通过服务端得到
                    limit: per_page,//每页显示的条数。laypage将会借助 count 和 limit 计算出分页数。
                    layout: ['prev', 'page', 'next'],
                    prev: '<i class="layui-icon layui-icon-left"></i>',
                    next: '<i class="layui-icon layui-icon-right"></i>',
                    theme: '#4873C1', //自定义主题
                    jump: function (obj, first) {//渲染
                        if (!first) { //一定要加此判断，否则初始时会无限刷新
                            $('input[name=page]').val(obj.curr);
                            form.submit();
                        }
                    }
                });
            },
            bindevent: function () {

                $('.icon-wenhaoxiao').on('mouseenter', function () {
                    var content = $(this).attr('lay-tips');
                    this.index = Layer.tips('<div class="wen_text">' + content + '</div>', this, {time: -1, maxWidth: 400, tips: [1, '#3A3D49']});
                }).on('mouseleave', function () {
                    Layer.close(this.index);
                });

                $(document).on('keyup change', '.text_title', function (e) {
                    if (e.metaKey || e.ctrlKey || [13, 10, 18, 91].indexOf(e.keyCode) > -1) return false;
                    var max = parseInt($(this).attr('maxlength'));
                    var value = $(this).val();
                    var length = value ? value.length : 0;
                    $(this).siblings('.text_calculate').text(length + '/' + max);
                });

                $('.text_title').trigger('change');

                //本地验证未通过时提示
                var postform = $('form[role=form]');
                postform.data("validator-options", validatoroptions);
                Form.api.bindevent(postform, function (data, ret) {
                    setTimeout(function () {
                        location.href = ret.url ? ret.url : "/";
                    }, 1000);
                    Layer.msg(ret.msg);
                    return false;
                }, function (data, ret) {
                    Layer.msg(ret.msg);
                    return false;
                });
            },
            charts: function (xAxisData, seriesData) {
                var _broken = Echarts.init(document.getElementById("tongji"));
                let option  = {
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: xAxisData,
                        axisLabel:{
                            textStyle:{
                                color:'#999999'
                            },
                        },
                        axisLine: {//x轴线条颜色
                            lineStyle: {
                                width:2,
                                color: '#ddd'
                            }
                        },
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    yAxis: {
                        type: 'value',
                        splitLine :{//网格线
                            show:false //关闭网格线
                        },
                        axisLine: {//x轴线条颜色
                            show: true,
                            lineStyle: {
                                width:2,
                                color: '#ddd'
                            }
                        },
                        axisLabel:{
                            textStyle:{
                                color:'#999',
                            },
                        },
                    },
                    grid: {
                        left: '0',
                        right: '30px',
                        bottom: '0',
                        top:'20px',
                        containLabel: true
                    },
                    series: [
                        {
                            data: seriesData,
                            type: 'line',
                            showSymbol: false,
                            lineStyle: {
                                width: 2,//外边线宽度
                                color:'#3074c1'//外边线颜色
                            },
                            areaStyle: {//区域填充渐变颜色
                                color: {
                                    type: 'linear',
                                    x: 0,
                                    y: 0,
                                    x2: 0,
                                    y2:1,
                                    colorStops: [{
                                        offset: 0, color: 'rgba(48,116,193, 0.5)' // 0% 处的颜色
                                    }, {
                                        offset: 1, color: 'rgba(48,116,193,0)' // 100% 处的颜色
                                    }],
                                    global: false // 缺省为 false
                                }
                            }
                        }
                    ]
                };
                _broken.setOption(option);
            }
        }
    };
    return Controller;
});
